package org.csu.storemanage.pojo;

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
//导入可选配置类
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
// 导入对应SMS模块的client
import com.tencentcloudapi.sms.v20190711.SmsClient;
// 导入要请求接口对应的request response类
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse;
import com.tencentcloudapi.sms.v20190711.models.SendStatus;
import jakarta.servlet.http.HttpSession;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import redis.clients.jedis.Jedis;


public class SendSms {

    public static SendStatus[] sendSms(String[] phoneNumber ) {

        SendStatus[] returString= {};

        try {
            Credential cred = new Credential("AKID4pSt50iEVfbL2e2B89TXURPBi1C9rLgs", "0lI9pIj6JGyZ1INFxRgi9QTRPEn6CF8y");

            // 实例化一个http选项，可选，没有特殊需求可以跳过
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setReqMethod("POST");
            httpProfile.setConnTimeout(60);
            httpProfile.setEndpoint("sms.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setSignMethod("HmacSHA256");
            clientProfile.setHttpProfile(httpProfile);
            SmsClient client = new SmsClient(cred, "ap-guangzhou", clientProfile);
            SendSmsRequest req = new SendSmsRequest();
            String sdkappid = "1400804966";
            req.setSmsSdkAppid(sdkappid);
            String sign = "Dram0nd公众号";
            req.setSign(sign);
            String templateID = "1744415";
            req.setTemplateID(templateID);

            String[] phoneNumbers = {"+86"+phoneNumber};
            req.setPhoneNumberSet(phoneNumber);

//         随机验证码
            int vode=ValidateCode.generateValidateCode(6);
            String code=String.valueOf(vode);
            Jedis jedis = new Jedis("127.0.0.1",6379);
            jedis.flushDB();
            jedis.setex("yzm",(long) 60,code);

            String[] templateParams = {code};
            req.setTemplateParamSet(templateParams);

            SendSmsResponse res = client.SendSms(req);

            System.out.println(SendSmsResponse.toJsonString(res));

            System.out.println(res.getRequestId());
            returString=res.getSendStatusSet();

        } catch (TencentCloudSDKException e) {
            e.printStackTrace();
        }

        return returString;
    }
}





